enum PaymentModel {
    // 借记卡
    Debit,
    // 信用卡
    Credit,
    // 贝宝支付
    Paypal,
}

impl PaymentModel {
    fn pay(&self, amount: u64) {
        match self {
            PaymentModel::Credit => pay_by_credit(amount),
            PaymentModel::Debit => pay_by_debit(amount),
            PaymentModel::Paypal => pay_by_redirect(amount)
        }
    }
}

fn main() {
    let payment_mode = get_saved_payment_mode();
    payment_mode.pay(512);
}

fn get_saved_payment_mode() -> PaymentModel {
    PaymentModel::Debit
}

// 一些网络支付处理程序
fn pay_by_credit(amt: u64) {
    println!("Processing credit payment of {}", amt);
}

fn pay_by_debit(amt: u64) {
    println!("Processing debit payment of {}", amt);
}

fn pay_by_redirect(amt: u64) {
    println!("Processing to paypal of {}", amt);
}